<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <% pageContext.setAttribute("APP_PATH", request.getContextPath());%>

    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">

    <script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>

    <link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
    <title>教师</title>
</head>

<jsp:include page="teacher_header.jsp"/>

<div class="container">
    <form class="form-horizontal " action="/UploadServlet" id="upload" enctype="multipart/form-data" method="post">
        <table class="table table-bordered">
            <div class="form-group">
                <tr>
                    <th>
                        <div class="col-sm-6">上传论文：</div>
                        (注意！！！ 格式：基于XX的系统.doc)
                    </th>
                    <th>
                        <input class="form-control" type="file" id="file" name="uploadFile">
                    </th>
                </tr>
            </div>

            <th> 温馨提示：请最后上传文件！</th>
            <th>
                <button type="submit" class="btn btn-success btn-sm" id="btn_upload_paper">上传</button>
                ${message}
                <br>
            </th>
        </table>
    </form>


    <form class="form-horizontal" id="add" method="post">
        <table class="table table-bordered">
            <div class="form-group">
                <tr>
                    <th>
                        <div class="col-sm-6">论文名称：</div>
                    </th>
                    <th>
                        <input class="form-control"
                               id="papername"
                               placeholder="论文名称应与上传的文件名（不含文件后缀）相同"
                               name="papername">
                    </th>
                </tr>
                <tr>
                    <th>
                        <div class="col-sm-6">第一作者：</div>
                    </th>
                    <th>
                        <input class="form-control" name="firstname">
                    </th>
                </tr>
                <tr>
                    <th>
                        <div class="col-sm-6">论文类型：</div>
                    </th>
                    <th>
                        <input class="form-control" name="papertypeid" placeholder="普通论文/核心论文/SCI论文/EI论文">
                    </th>
                </tr>
                <tr>
                    <th>
                        <div class="col-sm-6">其他作者：</div>
                    </th>
                    <th>
                        <input class="form-control" name="allname" value="多名作者以 / 分割：xxx/xx/xx">
                    </th>
                </tr>
                <tr>
                    <th>
                        <div class="col-sm-6">发表时间：</div>
                    </th>
                    <th>
                        <input class="form-control" type="text" id="endtime" name="endtime" value="格式：xxxx-xx-xx">
                    </th>
                </tr>
                <tr>
                    <th>
                        <div class="col-sm-6">支持基金：</div>
                    </th>
                    <th>
                        <input class="form-control" name="supportfun" value="没有则填：无">
                    </th>
                </tr>

            </div>
        </table>
        <div class="col-md-4 col-md-offset-4">
            <button class="btn btn-primary btn-lg" type="reset">重置</button>
            <button class="btn btn-success btn-lg" type="button" id="btn_add_paper">提交</button>
        </div>
    </form>

    <script>

        $("#btn_add_paper").click(function () {
            $.ajax({
                url: "${request.getContextPath()}/add_paper",
                type: "POST",
                dataType: "JSON",
                async: 'false',
                data: $("#add").serialize(),
                success: function (response) {
                    alert(response.message)
                    window.location.reload();
                },
                error: function (error) {
                    console.log(error)
                }
            });
        });

        var form = document.forms[0];
        $("#btn_upload_paper").click(function () {
            var file = document.getElementById("file");
            var name = document.getElementById("papername");

            //文件名为：
            filename = file.value.trim().replace(/^.+?\\([^\\]+?)(\.[^\.\\]*?)?$/gi, "$1");
        });

        $("#papername").blur(function () {
            var val = $("#papername").val();
            $("#upload_papername").val(val) //将上传论文需要的论文名 给后台
        });
    </script>
</div>


</body>
</html>
